﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using YJKView;

namespace EvacuationWidth.ControlLayer
{
	internal class LevelGeter
	{
		public List<Level> LstAllLevels
		{
			get
			{
				return this.m_lstAllLevels;
			}
			private set
			{
				this.m_lstAllLevels = value;
			}
		}

		internal LevelGeter(Document inputDoc)
		{
			this.m_doc = inputDoc;
			this.GetAllViewPlanLevel(this.m_doc);
		}

		internal bool GetSelectLevel(ref List<Level> selectLevel)
		{
			return FloorSelectManager.SelectFloorLevels(this.m_doc, ref selectLevel);
		}

		private void GetAllViewPlanLevel(Document doc)
		{
			this.LstAllLevels = new List<Level>();
			List<Level> list = new List<Level>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc).OfClass(typeof(ViewPlan));
			foreach (Element element in filteredElementCollector)
			{
				ViewPlan viewPlan = element as ViewPlan;
                if (viewPlan != null && (int)viewPlan.ViewType == 1 && viewPlan.GenLevel != null)
				{
					list.Add(viewPlan.GenLevel);
				}
			}
			list = (from k in list.Distinct(new LevelEqualCompare())
			orderby k.Elevation
			select k).ToList<Level>();
			this.LstAllLevels.AddRange(list);
		}

		private List<Level> m_lstAllLevels = new List<Level>();

		private Document m_doc;
	}
}
